//
//  NSString+WordsClass.m
//  UseLibSqlit3
//
//  Created by honeyrr on 2017/9/22.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "NSString+WordsClass.h"

@implementation NSString (WordsClass)

+(NSArray *)wordsClass:(NSArray *)wordsArr
{
    NSMutableArray *A = [NSMutableArray new];
    NSMutableArray *B = [NSMutableArray new];
    NSMutableArray *C = [NSMutableArray new];
    NSMutableArray *D = [NSMutableArray new];
    NSMutableArray *E = [NSMutableArray new];
    NSMutableArray *F = [NSMutableArray new];
    NSMutableArray *G = [NSMutableArray new];
    NSMutableArray *H = [NSMutableArray new];
    NSMutableArray *I = [NSMutableArray new];
    NSMutableArray *J = [NSMutableArray new];
    NSMutableArray *K = [NSMutableArray new];
    NSMutableArray *L = [NSMutableArray new];
    NSMutableArray *M = [NSMutableArray new];
    NSMutableArray *N = [NSMutableArray new];
    NSMutableArray *O = [NSMutableArray new];
    NSMutableArray *P = [NSMutableArray new];
    NSMutableArray *Q = [NSMutableArray new];
    NSMutableArray *R = [NSMutableArray new];
    NSMutableArray *S = [NSMutableArray new];
    NSMutableArray *T = [NSMutableArray new];
    NSMutableArray *U = [NSMutableArray new];
    NSMutableArray *V = [NSMutableArray new];
    NSMutableArray *W = [NSMutableArray new];
    NSMutableArray *X = [NSMutableArray new];
    NSMutableArray *Y = [NSMutableArray new];
    NSMutableArray *Z = [NSMutableArray new];
    
    for (NSDictionary *dict in wordsArr) {
        //拿到首字母
        NSString *before = [dict[@"en"] substringToIndex:1];
        if ([@"a" isEqualToString:before]) {
            [A addObject:dict];
        } else if ([@"b" isEqualToString:before]) {
            [B addObject:dict];
        } else if ([@"c" isEqualToString:before]) {
            [C addObject:dict];
        } else if ([@"d" isEqualToString:before]) {
            [D addObject:dict];
        } else if ([@"e" isEqualToString:before]) {
            [E addObject:dict];
        } else if ([@"f" isEqualToString:before]) {
            [F addObject:dict];
        } else if ([@"g" isEqualToString:before]) {
            [G addObject:dict];
        } else if ([@"h" isEqualToString:before]) {
            [H addObject:dict];
        } else if ([@"i" isEqualToString:before]) {
            [I addObject:dict];
        } else if ([@"j" isEqualToString:before]) {
            [J addObject:dict];
        } else if ([@"k" isEqualToString:before]) {
            [K addObject:dict];
        } else if ([@"l" isEqualToString:before]) {
            [L addObject:dict];
        } else if ([@"m" isEqualToString:before]) {
            [M addObject:dict];
        } else if ([@"n" isEqualToString:before]) {
            [N addObject:dict];
        } else if ([@"o" isEqualToString:before]) {
            [O addObject:dict];
        } else if ([@"p" isEqualToString:before]) {
            [P addObject:dict];
        } else if ([@"q" isEqualToString:before]) {
            [Q addObject:dict];
        } else if ([@"r" isEqualToString:before]) {
            [R addObject:dict];
        } else if ([@"s" isEqualToString:before]) {
            [S addObject:dict];
        } else if ([@"t" isEqualToString:before]) {
            [T addObject:dict];
        } else if ([@"u" isEqualToString:before]) {
            [U addObject:dict];
        } else if ([@"v" isEqualToString:before]) {
            [V addObject:dict];
        } else if ([@"w" isEqualToString:before]) {
            [W addObject:dict];
        } else if ([@"x" isEqualToString:before]) {
            [X addObject:dict];
        } else if ([@"y" isEqualToString:before]) {
            [Y addObject:dict];
        } else if ([@"z" isEqualToString:before]) {
            [Z addObject:dict];
        }
    }
    NSMutableArray *wordClassArr = [NSMutableArray arrayWithObjects:@{@"A":A},@{@"B":B},@{@"C":C},@{@"D": D},@{@"E": E},@{@"F": F},@{@"G": G},@{@"H": H},@{@"I": I},@{@"J": J},@{@"K": K},@{@"L": L},@{@"M": M},@{@"N": N},@{@"O": O},@{@"P": P},@{@"Q": Q},@{@"R": R},@{@"S": S},@{@"T": T},@{@"U": U},@{@"V": V},@{@"W": W},@{@"X": X},@{@"Y": Y},@{@"Z": Z}, nil];
    
    //遍历，返回首字母对应的单词个数
    for (NSDictionary *dict in wordClassArr) {
        NSLog(@" --- %@:%ld --- ", [dict allKeys][0], [[dict objectForKey:[dict allKeys][0]] count]);
    }
    return wordClassArr;
}

@end
